import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

# 绘制坐标系
""" 
arrow_length_ratio 箭头大小
linewidth 线宽
"""
ax.quiver(0, 0, 0, 5, 0, 0, color="r", arrow_length_ratio=0.1, label="x", linewidth=0.5)
ax.quiver(0, 0, 0, 0, 5, 0, color="g", arrow_length_ratio=0.1, label="y", linewidth=0.5)
ax.quiver(0, 0, 0, 0, 0, 5, color="b", arrow_length_ratio=0.1, label="z", linewidth=0.5)

# 设置坐标轴标签
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# 定义向量
va = (1, 1, 1)
vb = (-1, -1, -2)

# 绘制向量
ax.quiver(0, 0, 0, va[0], va[1], va[2], color="r", label="va")
ax.quiver(0, 0, 0, vb[0], vb[1], vb[2], color="g", label="vb")

# 设置坐标轴范围
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5)

# 设置标题
ax.set_title("3d向量")
# 显示图列
ax.legend()

# 显示图形
plt.show()
